<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text">
    <script>
        // 获取事件源
        const input = document.querySelector("input")
        // 添加键盘事件
        input.addEventListener("keydown", function () {
            console.log("按下键盘")
        })
        input.addEventListener("keyup", function () {
            console.log("松开键盘")
        })

        // 添加输入事件
        input.addEventListener("input", function () {
            console.log(input.value)
        })
    </script>
</body>
</html>